package com.ruoyi.controller;


import com.ruoyi.dto.AreaRiskAccess;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/riskEvaluate/areaRisk")
@Api(tags = {"区域综合评价评估"})
public class AreaRiskController {

    private double constructionX = 0.146163216;//建设施工点
    private double highConstructionX = 0.085261876;//高层建筑
    private double riskRoad = 0.048721072;//危货道路运输
    private double liquefiedPetroleum = 0.042630938;//液化石油气站场
    private double reservoirDam = 0.019488429;//水库大坝
    private double civilExplosive = 0.019488429;//民爆企业
    private double oilPipe = 0.012180268;//油气长输管道
    private double stadium = 0.007308161;//体育场馆
    private double waterTransportation = 0.007308161;//水上交通
    private double religiousServices = 0.004872107;//宗教活动场所
    private double sprayingEnterprise = 0.00365408;//喷涂企业
    private double shipConstruction = 0.002436054;//船舶修建企业
    private double gasStationX = 0.001218027;//加油站

    @PostMapping("/riskAccess")
    public Map riskAccess(@RequestBody AreaRiskAccess entity) throws UnknownHostException {

        Map map = new HashMap();
        int grade = 0;
        BigDecimal bigD = BigDecimal.ZERO;
        if (entity.getConstructionCount() != null) {//区域风险点个数
            bigD = BigDecimal.valueOf(entity.getConstructionCount()).multiply(BigDecimal.valueOf(constructionX)).add(bigD);
        }
        if (entity.getHighConstructionCount() != null) {//高层建筑 highConstructionCount
            bigD = BigDecimal.valueOf(entity.getHighConstructionCount()).multiply(BigDecimal.valueOf(highConstructionX)).add(bigD);
        }
        if (entity.getRiskRoadCount() != null) {//危货道路运输 riskRoadCount
            bigD = BigDecimal.valueOf(entity.getRiskRoadCount()).multiply(BigDecimal.valueOf(riskRoad)).add(bigD);
        }
        if (entity.getLiquefiedPetroleumCount() != null) {//液化石油气站场 liquefiedPetroleumCount
            bigD = BigDecimal.valueOf(entity.getLiquefiedPetroleumCount()).multiply(BigDecimal.valueOf(liquefiedPetroleum)).add(bigD);
        }
        if (entity.getReservoirDamCount() != null) {//水库大坝 reservoirDamCount
            bigD = BigDecimal.valueOf(entity.getReservoirDamCount()).multiply(BigDecimal.valueOf(reservoirDam)).add(bigD);
        }
        if (entity.getCivilExplosiveCount() != null) {//民爆企业 civilExplosiveCount
            bigD = BigDecimal.valueOf(entity.getCivilExplosiveCount()).multiply(BigDecimal.valueOf(civilExplosive)).add(bigD);
        }
        if (entity.getOilPipeCount() != null) {//油气长输管道 oilPipeCount
            bigD = BigDecimal.valueOf(entity.getOilPipeCount()).multiply(BigDecimal.valueOf(oilPipe)).add(bigD);
        }
        if (entity.getStadiumCount() != null) {//体育场馆 stadiumCount
            bigD = BigDecimal.valueOf(entity.getStadiumCount()).multiply(BigDecimal.valueOf(stadium)).add(bigD);
        }
        if (entity.getWaterTransportationCount() != null) {//水上交通 waterTransportationCount
            bigD = BigDecimal.valueOf(entity.getWaterTransportationCount()).multiply(BigDecimal.valueOf(waterTransportation)).add(bigD);
        }
        if (entity.getReligiousServicesCount() != null) {//宗教活动场所 religiousServicesCount
            bigD = BigDecimal.valueOf(entity.getReligiousServicesCount()).multiply(BigDecimal.valueOf(religiousServices)).add(bigD);
        }
        if (entity.getSprayingEnterpriseCount() != null) {//喷涂企业 sprayingEnterpriseCount
            bigD = BigDecimal.valueOf(entity.getSprayingEnterpriseCount()).multiply(BigDecimal.valueOf(sprayingEnterprise)).add(bigD);
        }
        if (entity.getShipConstructionCount() != null) {//船舶修建企业 shipConstructionCount
            bigD = BigDecimal.valueOf(entity.getShipConstructionCount()).multiply(BigDecimal.valueOf(shipConstruction)).add(bigD);
        }
        if (entity.getGasStationCount() != null) {//加油站 gasStationCount
            bigD = BigDecimal.valueOf(entity.getGasStationCount()).multiply(BigDecimal.valueOf(gasStationX)).add(bigD);
        }
        bigD.divide(BigDecimal.valueOf(entity.getAreaMeasure())).multiply(BigDecimal.valueOf(entity.getPopulationDensity())).multiply(BigDecimal.valueOf(entity.getEconomicDensity()));
        grade = bigD.intValue();
        if (grade < 0.04) {
            map.put("riskResult", "四级风险");
        } else if (grade >= 0.04 && grade < 0.06) {
            map.put("riskResult", "三级风险");
        } else if (grade >= 0.06 && grade < 0.08) {
            map.put("riskResult", "二级风险");
        } else if (grade >= 0.08) {
            map.put("riskResult", "一级风险");
        }
        map.put("grade", grade);
        map.put("number", entity.getNumber());
        return map;
    }

/*    private String getLocalMac(InetAddress inetAddress) {
        try {
            //获取网卡，获取地址
            byte[] mac = NetworkInterface.getByInetAddress(inetAddress).getHardwareAddress();
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < mac.length; i++) {
                if (i != 0) {
                    sb.append("-");
                }
                //字节转换为整数
                int temp = mac[i] & 0xff;
                String str = Integer.toHexString(temp);
                if (str.length() == 1) {
                    sb.append("0" + str);
                } else {
                    sb.append(str);
                }
            }
            return sb.toString();
        } catch (Exception exception) {
        }
        return null;
    }*/
}
